#===============================================================================
# export variables
#===============================================================================
ifeq ($(CFG_HI_EXPORT_FLAG),)
    ifneq ($(srctree),)
    KERNEL_DIR := $(srctree)

    SDK_DIR := $(shell cd $(KERNEL_DIR)/../../.. && /bin/pwd)
    else
    SDK_DIR := $(shell cd $(CURDIR)/../../../../.. && /bin/pwd)
    endif

    include $(SDK_DIR)/base.mak
endif

ifeq ($(wildcard $(MSP_DIR)/drv/otp/v100/otp_cfg.mak), $(MSP_DIR)/drv/otp/v100/otp_cfg.mak)
include $(MSP_DIR)/drv/otp/v100/otp_cfg.mak
endif

#===============================================================================
# local variables
#===============================================================================
EXTRA_CFLAGS += $(CFG_HI_KMOD_CFLAGS)

EXTRA_CFLAGS += -I$(MSP_UNF_INCLUDE)            \
                -I$(MSP_DRV_INCLUDE)            \
                -I$(COMMON_UNF_INCLUDE)         \
                -I$(COMMON_DRV_INCLUDE)         \
                -I$(MSP_DIR)/drv/otp/v100            \
                -I$(MSP_DIR)/drv/otp/v100/otpv200

ifeq ($(SDK_OTP_ARCH_VERSION), SDK_OTP_ARCH_VERSION_V3)
EXTRA_CFLAGS += -DSDK_OTP_ARCH_VERSION_V3
endif

#EXTRA_CFLAGS += -DSDK_OTP_VIRTUAL_DEBUG

MOD_NAME := hi_otp

obj-$(HI_DRV_BUILDTYPE) := $(MOD_NAME).o

$(MOD_NAME)-y := ./drv_otp.o ./drv_otp_intf.o ./drv_otp_common.o ./otpv200/hal_otp_v200.o
$(MOD_NAME)-y += ./otpv200/drv_otp_v200.o

BUILD_DIR := $(HI_OUT_DIR)/$(OBJ_NAME)/$(subst $(SDK_DIR)/,,$(CURDIR))

BUILD_DIR_MAKEFILE := $(BUILD_DIR)/Makefile

#===============================================================================
#   rules
#===============================================================================
.PHONY: all clean

all: $(BUILD_DIR_MAKEFILE)
	$(AT)make -C $(LINUX_DIR) ARCH=$(CFG_HI_CPU_ARCH) CROSS_COMPILE=$(HI_KERNEL_TOOLCHAINS_NAME)- M=$(BUILD_DIR) src=$(CURDIR) modules
	$(AT)test -d $(HI_MODULE_DIR) || mkdir -p $(HI_MODULE_DIR)
	$(AT)cp -f $(BUILD_DIR)/$(MOD_NAME).ko $(HI_MODULE_DIR)/

clean:
	$(AT)make -C $(LINUX_DIR) ARCH=$(CFG_HI_CPU_ARCH) CROSS_COMPILE=$(HI_KERNEL_TOOLCHAINS_NAME)- M=$(BUILD_DIR) src=$(CURDIR) clean
	$(AT)rm -rf $(HI_MODULE_DIR)/$(MOD_NAME).ko

$(BUILD_DIR_MAKEFILE): $(BUILD_DIR)
	$(AT)touch $@

$(BUILD_DIR):
	$(AT)mkdir -p $@

